package com.jiangjiang.eshop.wms.chain;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author Jianghaowen
 * @Date 2021/9/14
 * @Description: TODO
 * @Version V1.0
 **/
@Component
public class PurchaseInputOrderHandlerFactory {

    /**
     * 是否构建好了handler链条
     */
    private Boolean builtHandlerChain = false;

    /**
     * 更新采购入库单状态handler
     */
    @Autowired
    private UpdatePurchaseInputOrderStatusHandler updatePurchaseInputOrderStatusHandler;
    /**
     * 通知采购中心handler
     */
    @Autowired
    private InformPurchaseCenterHandler informPurchaseCenterHandler;
    /**
     * 更新本地库存handler
     */
    @Autowired
    private UpdateStockHandler updateStockHandler;
    /**
     * 通知调度中心handler
     */
    @Autowired
    private InformScheduleCenterHandler informScheduleCenterHandler;
    /**
     * 通知财务中心handler
     */
    @Autowired
    private InformFinanceCenterHandler informFinanceCenterHandler;

    public PurchaseInputOrderHandler getHandlerChain() {
        if(!builtHandlerChain){
            buildHandlerChain();
        }
        return updatePurchaseInputOrderStatusHandler;
    }


    /**
     * 构建责任链条
     */
    private void buildHandlerChain() {
        updatePurchaseInputOrderStatusHandler.setSuccessor(informPurchaseCenterHandler);
        informPurchaseCenterHandler.setSuccessor(updateStockHandler);
        updateStockHandler.setSuccessor(informScheduleCenterHandler);
        informScheduleCenterHandler.setSuccessor((informFinanceCenterHandler));

        builtHandlerChain = true;
    }

}
